package com.t26.web.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.t26.web.entity.Dev_user;
import com.t26.web.service.Dev_userService;
import com.t26.web.vo.Json;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Whenlean
 * @since 2021-06-12
 */

@RestController
@RequestMapping("/dev_user")
public class Dev_userController extends BaseController{

    @Autowired
    private Dev_userService devUserService;

    /**
     * 开发者登录
     * @Whenlean
     * @param body
     * @param request
     */
    @GetMapping("/login")
    public void userLogin(@RequestBody String body, HttpServletRequest request){
        JSONObject jsonObject = JSON.parseObject(body);
        String devCode = jsonObject.getString("devCode");
        String devPassword = jsonObject.getString("devPassword");
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("devCode",devCode);
        wrapper.eq("devPassword",devPassword);
        Dev_user devUser = devUserService.getOne(wrapper);
        if (StringUtils.isEmpty(devUser)){
            HttpSession session = request.getSession();
            session.setAttribute("devuser",devUser);
            Json.succ("登录成功");
        }else {
            Json.fail("登录失败");
        }

    }

}

